import { createStore, Store, useStore as useVuexStore } from 'vuex'
import { IRootState, IStoreType } from './types'

import login from './login/login'
import system from './system/system'

const store = createStore<IRootState>({
  state() {
    return {
      name: 'coderljm',
      age: 18
    }
  },
  mutations: {
    changeName(state) {
      state.name = 'lyy'
    }
  },
  getters: {},
  actions: {},
  modules: {
    login,
    system
  }
})

// 防止刷新的时候丢失vuex里面的值
export function setupStore() {
  store.dispatch('login/loadLocalLogin')
}

// 为了解决没有模块类型的问题
export function useStore(): Store<IStoreType> {
  return useVuexStore()
}

export default store
